#!/bin/sh

# It's ugly. Just trying to make this as simple as possible for the user.

if [ "$1" = "creovel" ]

	then 

		mv vendor/creovel/docs/Menu.txt doc/.info.creovel/

		NaturalDocs -ro -cs UTF-8 -i vendor/ -o HTML doc/creovel/ -p doc/.info.creovel/
		cp vendor/creovel/docs/documentation.css doc/creovel/styles/main.css
		cp vendor/creovel/docs/logo.png doc/creovel/styles/
		cp doc/.info.creovel/Menu.txt vendor/creovel/docs/Menu.txt 
	
		for f in `find doc/creovel -type f | xargs grep -l 'html'`; do
			sed -e 's/Generated by <a href/Style Based on <a href="http:\/\/mootools\.net">MooTools<\/a> Documentation. Generated By <a href/g' $f > $f.new
			mv $f.new $f
		done

	else

		rm -f doc/.info.application/Menu.txt

		echo "Format: 1.35" >> doc/.info.application/Menu.txt
		echo "" >> doc/.info.application/Menu.txt
		echo "" >> doc/.info.application/Menu.txt

		echo "Group: Models {" >> doc/.info.application/Menu.txt
		echo "" >> doc/.info.application/Menu.txt
		for f in `find app/models -type f -name '*.php'`; do
			file_name=`basename $f`
			name="${file_name%%.*}"
			echo "	File: $name (models/$file_name)" >> doc/.info.application/Menu.txt
		done
		echo "	}  # Group: Models" >> doc/.info.application/Menu.txt
		echo "" >> doc/.info.application/Menu.txt

		echo "Group: Controllers {" >> doc/.info.application/Menu.txt
		echo "" >> doc/.info.application/Menu.txt
		for f in `find app/controllers -type f -name '*.php'`; do
			file_name=`basename $f`
			name="${file_name%%.*}"
			echo "	File: $name (controllers/$file_name)" >> doc/.info.application/Menu.txt
		done
		echo "	}  # Group: Controllers" >> doc/.info.application/Menu.txt
		echo "" >> doc/.info.application/Menu.txt

		echo "Group: Helpers {" >> doc/.info.application/Menu.txt
		echo "" >> doc/.info.application/Menu.txt
		for f in `find app/helpers -type f -name '*.php'`; do
			file_name=`basename $f`
			name="${file_name%%.*}"
			echo "	File: $name (helpers/$file_name)" >> doc/.info.application/Menu.txt
		done
		echo "	}  # Group: Helpers" >> doc/.info.application/Menu.txt
		echo "" >> doc/.info.application/Menu.txt

		echo "Group: Index {" >> doc/.info.application/Menu.txt
		echo "" >> doc/.info.application/Menu.txt
		echo "	Index: Everything" >> doc/.info.application/Menu.txt
		echo "	File Index: Files" >> doc/.info.application/Menu.txt
		echo "	Function Index: Functions" >> doc/.info.application/Menu.txt
		echo "	}  # Group: Index" >> doc/.info.application/Menu.txt
		echo "" >> doc/.info.application/Menu.txt

		NaturalDocs -ro -cs UTF-8 -i app/ -o HTML doc/application/ -p doc/.info.application/
		cp vendor/creovel/docs/documentation.css doc/application/styles/main.css

		sed -e 's/padding: 70px 10px 0 0;/padding: 10px 10px 0 0;/g' doc/application/styles/main.css > main.new
		mv main.new doc/application/styles/main.css
fi
